

#import "PersonInfoViewController.h"
//显示 个人详情
@interface PersonInfoViewController ()<UITextFieldDelegate>

@end

@implementation PersonInfoViewController
- (void)dealloc {
    self.model = nil;
    [super dealloc];
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    [self showUI];
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(itemClick:)];
    self.navigationItem.rightBarButtonItem = item;
    [item release];
}

#pragma mark - 摆UI

- (void)showUI {
    for (int i = 0; i < 2; i++) {
        UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10, 64+40*i, 300, 30)];
        textField.borderStyle =UITextBorderStyleLine;
        textField.tag = 101+i;
        textField.delegate = self;
        [self.view addSubview:textField];
        [textField release];
    }
}
#pragma mark - 保存按钮 触发
- (void)itemClick:(UIBarButtonItem *)item {
    UITextField *field1 = (UITextField *)[self.view viewWithTag:101];
    UITextField *field2 = (UITextField *)[self.view viewWithTag:102];

    self.model.name = field1.text;
    self.model.phoneNumber = field2.text;
    
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITextField *field1 = (UITextField *)[self.view viewWithTag:101];
    UITextField *field2 = (UITextField *)[self.view viewWithTag:102];

    [field1 resignFirstResponder];
    [field2 resignFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [textField resignFirstResponder];
    return YES;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    UITextField *field1 = (UITextField *)[self.view viewWithTag:101];
    UITextField *field2 = (UITextField *)[self.view viewWithTag:102];
    field1.text = self.model.name;
    field2.text = self.model.phoneNumber;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
